<%@page import="javax.xml.registry.infomodel.User"%>
<%@ page language="java" import="java.util.*,net.fckeditor.*" pageEncoding="utf-8"%>

<%@include file="islogin.jsp"%>
<%@page import="com.ch7.common.*"%>
<%@page import="com.ch7.model.UserInfo"%>
<%@page import="com.ch7.common.DataConverter"%>
<%@page import="com.ch7.dal.Users"%>

<% request.setCharacterEncoding("utf-8");%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title>后台用户编辑与添加页</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<%
	
	String action = request.getParameter("action");
	String pageAction = "";
	String username=request.getParameter("username");
	UserInfo info = new UserInfo();
	Users users = new Users();
		if ("update".equals(action)) {
			info = users.getUsersInfo(username);
			if (info == null) {
				out.println("<script>alert('用户ID有误')；window.location.href='manager/users-manage.jsp';</script>");
			}
			info.setUsername(request.getParameter("id"));
			System.out.println(info.getUsername());
			info.setPassword(request.getParameter("txtPassword"));
			String email=request.getParameter("txtEmail");
			info.setEmail(email);
			info.setPower(request.getParameter("selPower"));
			if("update".equals(action)){
			users.update(info);
			}
			response.sendRedirect("users-manage.jsp");
			}
			
			if ("edit".equals(action) || "add".equals(action)) {
		info = users.getUsersInfo(username);
		if (info == null) {
		System.out.println("111");
		}
		pageAction = "update";
	}

			%>
			
</head>
<body>
<p>当前位置：用户编辑/添加</p>
	<form id="form1" name="form1" method="post" action="manager/users-edit.jsp">
		<table width="100%" border="1">
			<tr>
				<td>用户名称</td>
				<td><input type="text" name="textUserName" id="txtUserName"
					width=" 500px" value="<%=username%>"  readonly="readonly"/></td>
			</tr>
			<tr>
				<td>密码</td>
				<td><input type="password" name="txtPassword" id="txtPassword"
					width="500px" value="<%=info.getPassword()%>" /></td>
			</tr>
			<tr>
			<td>Email</td>
			<td><input type="text" name="txtEmail" id="txtEmail"
					width="500px" value="<%=info.getEmail()%>"/></td>
			</tr>
			<tr>
			<td>身份</td>
			<td>
			<select name="selPower"> 
			<option value="admin">管理员</option>
			<option value="user">一般用户</option>
			</select>
			</td>
			</tr>
			<tr>
			<td colspan="2">
			<input type="submit" name="button" id="button" value="提交"/>
			<input type="reset" name="button2" id="button2" value="重置"/>
			<input type="hidden" name="action" value="<%=pageAction%>"/>
			<input type="hidden" name="id" value="<%=info.getUsername()%>"/>
			</td>
			</tr>
			</table>
			</form>
</body>
</html>
